
# Global configurables
LIBTOOL=	libtool
CPPFLAGS=	#none
CFLAGS=		#none
LDFLAGS=	#none
DESTDIR=	#none
INSTALL=	install
INSTALL_DIR=	install -d -m 755
# Apache configurables
APXS=		apxs
SSL_INCLUDE=	/usr/include/openssl
APACHE_MOD_DIR=	$(shell ${APXS} -q LIBEXECDIR)
# Cyrus configurables
CC=		gcc
CYRUS_INCLUDE=	/usr/include/sasl
CYRUS_MOD_DIR=	/usr/lib/sasl2
INSTALL_LIB=	${INSTALL} -c -m 555

.PHONY: all clean
all: apache cyrus
clean: apache-clean cyrus-clean

${DESTDIR}${APACHE_MOD_DIR} ${DESTDIR}${CYRUS_MOD_DIR}:
	${INSTALL_DIR} $@

###########################################################################
# Apache 2.x module

.PHONY: apache
apache: mod_authn_gvn_userdb.la

mod_authn_gvn_userdb.la: mod_authn_gvn_userdb.c
	${APXS} -I${SSL_INCLUDE} ${CPPFLAGS} ${CFLAGS} ${LDFLAGS} \
	  -c mod_authn_gvn_userdb.c

.PHONY: apache-install
apache-install: ${DESTDIR}${APACHE_MOD_DIR}
	${APXS} -S LIBEXECDIR=${DESTDIR}${APACHE_MOD_DIR} \
	  -i mod_authn_gvn_userdb.la

.PHONY: apache-clean
apache-clean:
	-${LIBTOOL} --mode=clean rm -f mod_authn_gvn_userdb.la \
	  mod_authn_gvn_userdb.lo mod_authn_gvn_userdb.slo

###########################################################################
# Cyrus SASL module

CYRUS_OBJS=	cyrus_gvn_userdb.lo

.PHONY: cyrus
cyrus: libgvn_userdb.la

libgvn_userdb.la: ${CYRUS_OBJS} userdb.lo
	${LIBTOOL} --mode=link ${CC} -rpath ${CYRUS_MOD_DIR} ${LDFLAGS} \
	  -o libgvn_userdb.la ${CYRUS_OBJS} userdb.lo -lresolv

.SUFFIXES: .c .lo
.c.lo:
	${LIBTOOL} --mode=compile ${CC} ${CPPFLAGS} ${CFLAGS} \
	  -I${CYRUS_INCLUDE} -DBUILD_OUTSIDE_SASL -c $< -o $@

.PHONY: cyrus-install
cyrus-install: ${DESTDIR}${CYRUS_MOD_DIR}
	${LIBTOOL} --mode=install ${INSTALL_LIB} libgvn_userdb.la \
	  ${DESTDIR}${CYRUS_MOD_DIR}

.PHONY: cyrus-clean
cyrus-clean:
	-${LIBTOOL} --mode=clean rm -f libgvn_userdb.la ${CYRUS_OBJS}
